feat: add tool script safety guard#113
Open
xyxhhhhh wants to merge 3 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
==========================================
Coverage ? 87.72126%
==========================================
Files ? 476
Lines ? 44744
Branches ? 0
==========================================
Hits ? 39250
Misses ? 5494
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
ccf18ad to
8bc9647
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
Rook1ex
added a commit
to trpc-group/cla-database
that referenced
this pull request
Jul 2, 2026
8bc9647 to
343a75c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
Resolves #90
本次实现了Tool Script Safety Guard,用于在 Tool / Skill / MCP Tool /
CodeExecutor 执行脚本或命令前进行安全扫描、策略判断、拦截和审计。
主要能力:
allow/deny/needs_human_review三类决策decision、risk_level、rule_id、evidence、recommendationtool.safety.*attributesBashTool和UnsafeLocalCodeExecutor提供 opt-in 接入,不改变默认历史行为
风险覆盖
已覆盖的风险类型:
.env、~/.ssh、凭据文件访问等curl、wget、requests、aiohttp、socket、非白名单域名访问等
subprocess、os.system、shell 管道、命令替换、后台进程、提权命令等
pip install、python -m pip install、npm install、apt install等额外补充的高价值场景:
base64 | shpython -cbash -c/sh -c.env/~/.ssh路径curl --data-binary @.envfind -deletexargs rm -rfos.getenv("API_TOKEN")外传兼容性
核心执行链路接入采用 opt-in 方式,避免破坏现有默认行为。
BashTool和UnsafeLocalCodeExecutor默认保持原有执行逻辑。用户可以通过参数enable_safety_guard=True显式启用安全扫描。启用后:
deny会在执行前阻断脚本或命令needs_human_review默认只记录到safety_report、audit 和 telemetry,不阻断执行
block_on_review=Trueallow会继续执行验收映射
trpc_agent_sdk/tools/safety/_rules.py、_scanner.pytrpc_agent_sdk/tools/safety/_policy.py、examples/ tool_safety/tool_safety_policy.yamlallow、deny、needs_human_reviewtrpc_agent_sdk/tools/safety/_filter.py、_wrapper.pytrpc_agent_sdk/tools/file_tools/_bash_tool.py、trpc_agent_sdk/code_executors/local/_unsafe_local_code_executor.pydecision、risk_level、rule_id、risk_type、evidence、recommendationtrpc_agent_sdk/tools/safety/_audit.py、_telemetry.pyscripts/tool_safety_check.pyscripts/tool_safety_manifest_report.pyexamples/tool_safety/samples/manifest.yaml、examples/ tool_safety/all_reports.jsonexamples/tool_safety/README.md样例校验
样例语料由 manifest 驱动:
examples/tool_safety/samples/manifest.yamlexamples/tool_safety/all_reports.jsonscripts/tool_safety_manifest_report.py当前 manifest 状态:
验证
已通过相关测试和校验:
当前结果:
tests/tools/safety:82 passedflake8通过yapf --diff无格式 diff_policy.py和_rules.pypatch coverage 缺失分支测试也验证了单文件 CLI 扫描:
结果:
deny,命中BASH_RECURSIVE_DELETE。文档
新增 examples/tool_safety/README.md,说明: